package Test4;

import java.util.Scanner;

public class CarTest {
    public static void main(String[] args) {
        //需求：
        //定义数组存储3部汽车对象
        //汽车的属性：品牌，价格，颜色
        //创建三个汽车对象，数据通过键盘录入而来，并把数据存入到数组当中

        //1.定义数组
        Car[] arr = new Car[3];

        //2.创建对象
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "辆汽车的品牌：");
            String brand = sc.next();
            System.out.println("请输入第" + (i + 1) + "辆汽车的价格：");
            double price = sc.nextDouble();
            System.out.println("请输入第" + (i + 1) + "辆汽车的颜色：");
            String color = sc.next();
            Car car = new Car(brand, price, color);
            arr[i] = car;
        }

        //3.遍历
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getBrand() + "," + arr[i].getPrice() + "," + arr[i].getColor());
        }
    }
}
